﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlTypes;
using System.Linq;
using System.Text;


namespace nadModel.displayBoard
{
    public partial class MesSetupStatusEntityProcess : AbstractEntityProcess
    {

        public override AbstractEntity[] PackEntity(object obj)
        {
            //pack entries
            List<MesSetupStatusEntity> entryList = new List<MesSetupStatusEntity>();

            MesSetupStatusEntity entry;
            try
            {
                DataTable dt = (DataTable)obj;
                if (dt == null)
                {
                    return null;
                }

                foreach (DataRow item in dt.Rows)
                {
                    entry = new MesSetupStatusEntity();
                    entry.Description = item[MesSetupStatusEntity.DESCRIPTION].ToString();
                    entry.Job = item[MesSetupStatusEntity.JOB].ToString();
                    entry.Machine = item[MesSetupStatusEntity.MACHINE].ToString();
                    entry.Part = item[MesSetupStatusEntity.PART].ToString();
                    entry.Type = item[MesSetupStatusEntity.TYPE].ToString();
                    entry.ActualSetupCompleted = decimal.Parse(item[MesSetupStatusEntity.ACTUALSETUPCOMPLETED].ToString());
                    entry.ColorFrom = item[MesSetupStatusEntity.COLORFROM].ToString();
                    entry.Differece = decimal.Parse(item[MesSetupStatusEntity.DIFFERECE].ToString());
                    entry.ExpectedSetupcompleted = decimal.Parse(item[MesSetupStatusEntity.EXPECTEDSETUPCOMPLETED].ToString());
                    entry.ST1ActualSetupProgress = decimal.Parse(item[MesSetupStatusEntity.ST1ACTUALSETUPPROGRESS].ToString());
                    entry.ST1ActualSetupStart = item[MesSetupStatusEntity.ST1ACTUALSETUPSTART].ToString();
                    entry.ST1ActualSetupWorkerName = item[MesSetupStatusEntity.ST1ACTUALSETUPWORKERNAME].ToString();
                    entry.ST1ActualSetupWorkerNo = item[MesSetupStatusEntity.ST1ACTUALSETUPWORKERNO].ToString();
                    entry.ST1SetupStd = decimal.Parse(item[MesSetupStatusEntity.ST1SETUPSTD].ToString());
                    entry.ST2ActualSetupProgress = decimal.Parse(item[MesSetupStatusEntity.ST2ACTUALSETUPPROGRESS].ToString());
                    entry.ST2ActualSetupStart = item[MesSetupStatusEntity.ST2ACTUALSETUPSTART].ToString();
                    entry.ST2ActualSetupWorkerName = item[MesSetupStatusEntity.ST2ACTUALSETUPWORKERNAME].ToString();
                    entry.ST2ActualSetupWorkerNo = item[MesSetupStatusEntity.ST2ACTUALSETUPWORKERNO].ToString();
                    entry.ST2SetupStd = decimal.Parse(item[MesSetupStatusEntity.ST2SETUPSTD].ToString());
                    entry.ST3ActualSetupProgress = decimal.Parse(item[MesSetupStatusEntity.ST3ACTUALSETUPPROGRESS].ToString());
                    entry.ST3ActualSetupStart = item[MesSetupStatusEntity.ST3ACTUALSETUPSTART].ToString();
                    entry.ST3ActualSetupWorkerName = item[MesSetupStatusEntity.ST3ACTUALSETUPWORKERNAME].ToString();
                    entry.ST3ActualSetupWorkerNo = item[MesSetupStatusEntity.ST3ACTUALSETUPWORKERNO].ToString();
                    entry.ST3SetupStd = decimal.Parse(item[MesSetupStatusEntity.ST3SETUPSTD].ToString());
                    entry.ToColor = item[MesSetupStatusEntity.TOCOLOR].ToString();

                    entryList.Add(entry);
                }
            }
            catch (Exception ex)
            {
                Log("ERROR: error packing entity", LogLevel.FATAL);
                Log(ex.ToString(), LogLevel.FATAL);
                throw ex;
            }
            return (AbstractEntity[])entryList.ToArray();

        }
    }
}
